package hibernate.web;

import hibernate.fileControler.MyException;
import hibernate.model.Dokumanlar;
import hibernate.service.EmmyService;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@SuppressWarnings("serial")
@Component("DokumanlarBean")
@Scope("session")
public class DokumanlarBean implements BeanService {

	@Autowired
	private transient EmmyService emmyService;
	
	private Dokumanlar selectedDoc;	
	private List<Dokumanlar> docList;
	
	@SuppressWarnings("unchecked")
	@Override
	@PostConstruct
	public void init() {
		docList = (List<Dokumanlar>) emmyService.findAll(new Dokumanlar());
	}

	@Override
	public String restart() {
		init();
		return "list";
	}

	@Override
	public String deleteView() {
		emmyService.delete(selectedDoc.getDocid());
		init();
		return "list";
	}

	@Override
	public String viewNew() {
		selectedDoc= new Dokumanlar();
		return "detail";
	}

	@Override
	public String viewDetail() {/*
		List<Dokumanlar> valueList = (List<Dokumanlar>) dokumanTable.getValue();	
		System.out.println("table size : "+valueList.size());		
		Iterator<SimpleRowKey> keys = dokumanTable.getSelection().getKeys();
		
		if(keys.hasNext()){
			currentDoc= valueList.get(keys.next().intValue());
			System.out.println("dolu = "+currentDoc.getDocid());
			return "detail";
		}else{
			System.out.println("bo�ta");
			return null;
		}*/ return"detay";
	}

	@Override
	public String SaveOrUpdate() throws MyException {
		emmyService.saveOrUpdate(selectedDoc);
		init();
		return "list";
	}	
	
	@SuppressWarnings("unchecked")
	public String getAygitDokumanlari(long id){		
		docList = (List<Dokumanlar>) emmyService.getQuery("findDocAygitid", "dAygitid", id);
		return "list";
	}
	
	@Override
	public String createQuery() {		
		return null;
	}

	@Override
	public void getSession() {
		// TODO Auto-generated method stub
		
	}

	public Dokumanlar getSelectedDoc() {
		return selectedDoc;
	}

	public void setSelectedDoc(Dokumanlar selectedDoc) {
		this.selectedDoc = selectedDoc;
	}

	public List<Dokumanlar> getDocList() {
		return docList;
	}

	public void setDocList(List<Dokumanlar> docList) {
		this.docList = docList;
	}
}